<?php
$myTeam = new SelectedTeam(getSelectedTeam($loggedInTeam->id), $loggedInTeam->teamName);
$myTeam->id = $loggedInTeam->id;

$players = $myTeam->getPlayers();
?>
<script>
var reqPositions = ['LBP', 'FB', 'RBP', 'LHBF', 'CHB', 'RHBF', 'LW', 'C', 'RW', 'LHFF', 'CHF', 'RHFF', 'LFP', 'FF', 'RFP', 'R', 'F1', 'F2', 'E1', 'E2', 'E3', 'E4', 'E5'];
function validateForm(frm) {
	alreadyFound = "";
	for (i=0; i<reqPositions.length; i++) {
		if (document.getElementById(reqPositions[i]) != null) {
			selectedValue = document.getElementById(reqPositions[i]).options[document.getElementById(reqPositions[i]).selectedIndex].value;
			if (selectedValue != -1) {
				if (alreadyFound.indexOf("," + selectedValue + ",") != -1) {
					alert(document.getElementById(reqPositions[i]).options[document.getElementById(reqPositions[i]).selectedIndex].text + " has been selected more than once.");
					return;
				}
				else {
					alreadyFound += "," + selectedValue + ","; 
				}
			}
		}
	}
	
	frm.submit();
}
</script>
<?$ltiReplacements = $myTeam->getLtiReplacements();?>
<form action="submitEditTeam.php">
<table width="100%" cellspacing="10">
	<tr>
		<td width="5%"><b>B:</b>
		<td width="30%"><? echo getSelectString('LBP', $players, $myTeam, null, null);?></td><td width="2%">|</td>
		<td width="30%"><? echo getSelectString('FB', $players, $myTeam, null, null);?></td><td width="2%">|</td>
		<td width="30%"><? echo getSelectString('RBP', $players, $myTeam, null, null);?></td>
	</tr>
	<tr>
		<td><b>HB:</b>			
		<td><? echo getSelectString('LHBF', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('CHB', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('RHBF', $players, $myTeam, null, null);?></td>
	</tr>			
	<tr>
		<td><b>C:</b>			
		<td><? echo getSelectString('LW', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('C', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('RW', $players, $myTeam, null, null);?></td>
	</tr>			
	<tr>
		<td><b>HF:</b>			
		<td><? echo getSelectString('LHFF', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('CHF', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('RHFF', $players, $myTeam, null, null);?></td>
	</tr>			
	<tr>
		<td><b>F:</b>			
		<td><? echo getSelectString('LFP', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('FF', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('RFP', $players, $myTeam, null, null);?></td>
	</tr>			
	<tr>
		<td><b>R:</b>			
		<td><? echo getSelectString('R', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('F1', $players, $myTeam, null, null);?><td>|</td>
		<td><? echo getSelectString('F2', $players, $myTeam, null, null);?></td>
	</tr>
	<tr>
		<td valign="top"><b>RES:</b></td>
		<td colspan="6">
		<?
		$ltis = $myTeam->getLti();
		$ltiCount = count($ltis);
		
		$reserves = $myTeam->getReserves();
		$count = count($reserves);
		for ($i = 0; $i < $count; $i++) {
			if ($i > 0) {
				echo " | ";
			}
			echo getPlayerDisplay($reserves[$i], null);
		}
		?>
		</td>
	</tr>
	<?if ($ltiCount > 0) {?>	
	<tr>
		<td valign="top"><b>LTI:</b></td>
		<td colspan="6">
		<?
		for ($i = 0; $i < $ltiCount; $i++) {
			if ($i > 0) {
				echo ", ";
			}
			echo getPlayerDisplay($ltis[$i], null);
		}
		?>
		</td>
	</tr>
	<?}?>	
	<tr>
		<td><input type="button" value="Update" onclick="validateForm(this.form)" class="buttonStyle"></td>
	</tr>			
</table>
</form>
